package com.liuweiheng.cloudproviderpayment8002.mq.direct;

import com.liuweiheng.cloudproviderpayment8002.util.RabbitMQUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

public class Provider {

    public static final String INFO = "info";

    public static final String ERROR = "error";

    public static final String WARNING = "warning";

    public static final String EXCHANGE_NAME = "logs-direct";

    public static final String EXCHANGE_TYPE = "direct";


    public static void main(String[] args) throws IOException {
        //获取MQ连接
        Connection connection = RabbitMQUtil.getConnection();

        // 创建通道
        Channel channel = connection.createChannel();

        // 声明交换机和类型
        channel.exchangeDeclare(EXCHANGE_NAME, EXCHANGE_TYPE, true);

        // 发布消息，并指定路由
        channel.basicPublish(EXCHANGE_NAME, WARNING, null, "Hello Dirct".getBytes());

        // 关闭连接，释放资源
        RabbitMQUtil.closeConnection(channel, connection);

    }


}
